package com.gxa.customer.controller;


import com.gxa.common.commons.R;
import com.gxa.common.pojo.AppUserHouse;
import com.gxa.common.utils.FileUtils;
import com.gxa.customer.service.AppUserHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/customer/appUserHouse")
public class AppUserHouseController {


    @Autowired
    private AppUserHouseService appUserHouseService;

    /**
     * 添加房产
     */
    @PostMapping(value = "/addHouse")
    public R addHouse(MultipartFile file, AppUserHouse appUserHouse, HttpServletRequest request){
        String url= FileUtils.fileUpload("/appUser",file,request);
        System.out.println(url);
        appUserHouse.setHouseImage(url);
        appUserHouseService.insertAppUserHouse(appUserHouse);
        R r=new R();
        r.setCode(200);
        r.setMsg("房产添加成功");
        return r;
    }


    /**
     * 根据用户id查询所有房产
     */
    @GetMapping(value = "/selectAllHouseById")
    public R selectAllHouseById(Long appUserId){
        List<AppUserHouse> appUserHouseList=appUserHouseService.selectAllHouseById(appUserId);
        R r =new R();
        if(appUserHouseList!=null){
            r.setCode(200);
            r.setMsg("查询成功!");
            r.setData(appUserHouseList);
        }else{
            r.setCode(500);
            r.setMsg("查询失败!");
        }
        return r;
    }










}
